//
//  LineView.m
//  yuikemall
//
//  Created by Gang.Wang on 12-6-2.
//  Copyright (c) 2012年 yuike. All rights reserved.
//

#import "LineView.h"
#import "header.h"


@interface LineView()
{
    CALayer * solidUnderline;
    CALayer *bot;

    CGColorRef  lineColor_;
}
- (void) privateInit;
@end

@implementation LineView

- (void) dealloc
{
    YRelease(solidUnderline)
    YRelease(bot)
    
    [super dealloc];
}

- (id) initWithCGColor:(CGColorRef ) colorRef
{
    self = [super init];
    if (self) {
        lineColor_ =  colorRef;
        [self privateInit];
    }
    
    return self;
}

- (id) init
{
    self = [super init];
    if (self) 
    {
        lineColor_ = [UIColor colorWithWhite:0.90f alpha:1].CGColor;
        [self privateInit];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        lineColor_ = [UIColor colorWithWhite:0.90f alpha:1].CGColor;
        [self privateInit];
    }
    return self;
}

- (void) privateInit
{
    if (!solidUnderline) 
    {
        solidUnderline = [[CALayer layer] retain];
        [[self layer] addSublayer:solidUnderline];
    }
    
    solidUnderline.backgroundColor = lineColor_;
        
    if (!bot) 
    {
       bot = [[CALayer layer] retain]; 
       [solidUnderline addSublayer:bot];
    }
        
    bot.backgroundColor = [UIColor whiteColor].CGColor;    
    [self reAdjustLayout];
}

- (void) setFrame:(CGRect)frame
{
    [super setFrame:frame];
    [self reAdjustLayout];
}

- (void) reAdjustLayout
{
    CGRect frame = self.frame;
    frame.size.height = 2;
//    [super setFrame:frame];
    
    bot.frame = CGRectMake(0, 1, self.width, 1);
    solidUnderline.frame = CGRectMake(0, 0, self.width, 2);

}

@end
